//
//  CLNavRightBtn.m
//  togetherLBS
//
//  Created by 丁益 on 15/12/11.
//  Copyright © 2015年 celi. All rights reserved.
//

#import "CLNavRightBtn.h"

@interface CLNavRightBtn()
@end

@implementation CLNavRightBtn

- (id)initWIthImageName:(NSString*)imageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action{
    CLNavRightBtn *button = [[CLNavRightBtn alloc] init];
    [button setBackgroundImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageNamed:highImageName] forState:UIControlStateHighlighted];
    // 设置按钮的尺寸为背景图片的尺寸
    button.size = button.currentBackgroundImage.size;
    
    button.lab = [[UILabel alloc]initWithFrame:CGRectMake(22, 0, 10, 10)];
    button.lab.backgroundColor = [UIColor redColor];
    button.lab.layer.cornerRadius = 5.0;
    button.lab.layer.masksToBounds = YES;
    [button addSubview:button.lab];
    button.lab.hidden = YES;
    
    // 监听按钮点击
    [button addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return button;
}

/**
 *  创建导航栏上带红点的按钮
 */
+ (CLNavRightBtn *)itemWIthImageName:(NSString*)imageName highImageName:(NSString *)highImageName target:(id)target action:(SEL)action{
    
    CLNavRightBtn *button = [[CLNavRightBtn alloc]initWIthImageName:imageName highImageName:highImageName target:(id)target action:(SEL)action];
    return button;
}

/**
 *  显示红点
 */
- (void)showRedFlg:(CLNavRightBtn*)btn{
    btn.lab.hidden = NO;
}

/**
 *  隐藏红点
 */
- (void)hiddenRedFlg:(CLNavRightBtn*)btn{

    btn.lab.hidden = YES;
}

@end
